// pages/personInfo/personInfo.js
import {
  AuthModel
} from '../../models/authData.js'
let authModel = new AuthModel()
import {
  OrderModel
} from '../../models/hdd/orderData.js'
let orderModel = new OrderModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    personalData: '',
    skillGradeText: '',
    authenticationStatus: '1',
    workExp: [],
    eduExp: [],
    trainExp: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.FId) {
      wx.setNavigationBarTitle({
        title: '维修师傅'
      })
      wx.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: '#FF7136',
        animation: {
          duration: 400,
          timingFunc: 'easeIn'
        }
      })
      wx.showLoading()
      orderModel.getPersonByOrder({
        args: {
          orderId: options.FId,
        }
      }).then(res => {
        let ifAuthentication
        let status
        if (res.data.data.resumeData.authenticationInfoList[0]) {
          if (res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'New' || res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Back') { } else {
            if (res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Auditing') {
              status = '2'
            }
            if (res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Audited') {
              status = '3'
            }
          }
        } else {
          status = '1'
        }
        var FSkillGradeText = ''
        if (res.data.data.resumeData.authenticationInfoList[0]) {
          FSkillGradeText = res.data.data.resumeData.authenticationInfoList[0].FSkillGradeText
        }
        this.setData({
          skillGradeText: FSkillGradeText ? FSkillGradeText : '',
          authenticationStatus: status,
          workExp: res.data.data.resumeData.workList ? res.data.data.resumeData.workList : [],
          eduExp: res.data.data.resumeData.expList ? res.data.data.resumeData.expList : [],
          trainExp: res.data.data.resumeData.trainingUndergoList ? res.data.data.resumeData.trainingUndergoList : [],
          personalData: res.data.data.data
        })
        wx.hideLoading()
      })
    } else {
      this.initHHDView()
    }
  },

  initHHDView() {
    wx.setNavigationBarTitle({
      title: '个人简历'
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#3B80FE',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    this.setData({
      personalData: JSON.parse(options.personalData)
    })
    wx.showLoading()
    authModel.getSelfAuthData()
      .then(res => {
        let ifAuthentication
        let status
        if (res.data.data.resumeData.authenticationInfoList[0]) {
          if (res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'New' || res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Back') {} else {
            if (res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Auditing') {
              status = '2'
            }
            if (res.data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Audited') {
              status = '3'
            }
          }
        } else {
          status = '1'
        }
        var FSkillGradeText = ''
        if (res.data.data.resumeData.authenticationInfoList[0]) {
          FSkillGradeText = res.data.data.resumeData.authenticationInfoList[0].FSkillGradeText
        }
        this.setData({
          skillGradeText: FSkillGradeText ? FSkillGradeText : '',
          authenticationStatus: status,
          workExp: res.data.data.resumeData.workList ? res.data.data.resumeData.workList : [],
          eduExp: res.data.data.resumeData.expList ? res.data.data.resumeData.expList : [],
          trainExp: res.data.data.resumeData.trainingUndergoList ? res.data.data.resumeData.trainingUndergoList : [],
        })
        wx.hideLoading()
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})